<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var str = "今天的天气真不错!";
        for (var i = 0; i < str.length; i++) {
            console.log(str[i]);
        }
        console.log('/************* 倒序输出 **************/');
        for (var i = str.length - 1; i >= 0; i--) {
            console.log(str[i]);
        }
        console.log('/************* 有多少个天 **************/');
        var str = "今天的天气真不错啊!";
        var count = 0;
        for (var i = 0; i < str.length; i++) {
            if (str[i] == '天') {
                count++;
            }
            console.log('有%s个天', count);
        }
        console.log('----------------------')
        var str = "今天的天气真不错啊!";
        var str2 = '';
        for (var i = 0; i < str.length; i++) {
            if (str[i] == '天') {
                // 理论实现
                //str[i] = '*';
                // 拼接星号
                str2 += '*';
            } else { // 拼接正常的字符
                str2 += str[i];
            }
        }
        console.log(str2);
    </script>
</body>

</html>